/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import jeeobserver.JvmObserver;
import jeeobserver.Observer;
import jeeobserver.server.settings.Condition.NumberCondition;
import jeeobserver.server.settings.Condition.SizeCondition;
import jeeobserver.server.settings.Condition.TextCondition;

/**
 * The Class JvmExclusionRule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public class JvmExclusionRule extends Rule {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The cpu usage percentage condition. */
	 private NumberCondition cpuUsagePercentageCondition;

	 /** The heap memory size condition. */
	 private SizeCondition heapMemorySizeCondition;

	 /** The non heap memory size condition. */
	 private SizeCondition nonHeapMemorySizeCondition;

	 public boolean iObserverInRule(JvmObserver observer) {

			if (super.isObserverInRule(observer)) {
				 if ((this.getCpuUsagePercentageCondition() == null) || this.getCpuUsagePercentageCondition().checkValue(observer.getCpuUsagePercentage())) {
						if ((this.getHeapMemorySizeCondition() == null) || this.getHeapMemorySizeCondition().checkByteValue(observer.getHeapMemoryUsedBytes())) {
							 if ((this.getNonHeapMemorySizeCondition() == null) || this.getNonHeapMemorySizeCondition().checkByteValue(observer.getNonHeapMemoryUsedBytes())) {
									return true;
							 }
						}
				 }
			}

			return false;
	 }

	 /**
	  * Gets the cpu usage percentage condition.
	  *
	  * @return the cpu usage percentage condition
	  */
	 public NumberCondition getCpuUsagePercentageCondition() {
			return this.cpuUsagePercentageCondition;
	 }

	 /**
	  * Sets the cpu usage percentage condition.
	  *
	  * @param cpuUsagePercentageCondition the new cpu usage percentage condition
	  */
	 public void setCpuUsagePercentageCondition(NumberCondition cpuUsagePercentageCondition) {
			this.cpuUsagePercentageCondition = cpuUsagePercentageCondition;
	 }

	 /**
	  * Gets the heap memory size condition.
	  *
	  * @return the heap memory size condition
	  */
	 public SizeCondition getHeapMemorySizeCondition() {
			return this.heapMemorySizeCondition;
	 }

	 /**
	  * Sets the heap memory size condition.
	  *
	  * @param heapMemorySizeCondition the new heap memory size condition
	  */
	 public void setHeapMemorySizeCondition(SizeCondition heapMemorySizeCondition) {
			this.heapMemorySizeCondition = heapMemorySizeCondition;
	 }

	 /**
	  * Gets the non heap memory size condition.
	  *
	  * @return the non heap memory size condition
	  */
	 public SizeCondition getNonHeapMemorySizeCondition() {
			return this.nonHeapMemorySizeCondition;
	 }

	 /**
	  * Sets the non heap memory size condition.
	  *
	  * @param nonHeapMemorySizeCondition the new non heap memory size condition
	  */
	 public void setNonHeapMemorySizeCondition(SizeCondition nonHeapMemorySizeCondition) {
			this.nonHeapMemorySizeCondition = nonHeapMemorySizeCondition;
	 }
}
